#include <QDebug>
#include <time.h>
#include <QTime>
#include <QPluginLoader>

#include "unionhmidll_global.h"
#include "WorkThreadManage/hmithreadmanage.h"
#include "ui_mainwindow.h"

void HmiThread :: FastTimerUpdate(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->FastTimerLoop();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->FastTimerLoop();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: SlowTimerUpdate(){
    if(RunLed == true){
        this->ui->RunLed->setStyleSheet(("background-color: rgb(50,150,30)"));
        RunLed = false;
    }
    else{
        this->ui->RunLed->setStyleSheet(("background-color: rgb(215,215,215)"));
        RunLed = true;
    }
    this->HmiMessageBoxShow();

    switch (ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->SlowTimerLoop();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->SlowTimerLoop();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_vPower(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                if(this->pRobControllerHMI->onbtnclicked_vPower() == false){
                    this->ui->vPower->setStyleSheet(("background-color: rgb(225,225,225)"));
                    if(this->ui->XN->isEnabled()){
                        this->ui->XN->setEnabled(false);  this->ui->XP->setEnabled(false);
                        this->ui->YN->setEnabled(false);  this->ui->YP->setEnabled(false);
                        this->ui->ZN->setEnabled(false);  this->ui->ZP->setEnabled(false);
                        this->ui->AN->setEnabled(false);  this->ui->AP->setEnabled(false);
                        this->ui->BN->setEnabled(false);  this->ui->BP->setEnabled(false);
                        this->ui->CN->setEnabled(false);  this->ui->CP->setEnabled(false);
                        this->ui->E1N->setEnabled(false); this->ui->E1P->setEnabled(false);
                        this->ui->E2N->setEnabled(false); this->ui->E2P->setEnabled(false);
                    }
                    this->ui->XN->setStyleSheet(("color: rgb(0,0,0)"));  this->ui->XP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->YN->setStyleSheet(("color: rgb(0,0,0)"));  this->ui->YP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->ZN->setStyleSheet(("color: rgb(0,0,0)"));  this->ui->ZP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->AN->setStyleSheet(("color: rgb(0,0,0)"));  this->ui->AP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->BN->setStyleSheet(("color: rgb(0,0,0)"));  this->ui->BP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->CN->setStyleSheet(("color: rgb(0,0,0)"));  this->ui->CP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->E1N->setStyleSheet(("color: rgb(0,0,0)")); this->ui->E1P->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->E2N->setStyleSheet(("color: rgb(0,0,0)")); this->ui->E2P->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel1->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel2->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel3->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel4->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel5->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel6->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel7->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel8->setStyleSheet(("color: rgb(0,0,0)"));
                }
                else {
                    this->ui->vPower->setStyleSheet(("background-color: rgb(50,150,30)"));
                    if(!(this->ui->XN->isEnabled())){
                        this->ui->XN->setEnabled(true);  this->ui->XP->setEnabled(true);
                        this->ui->YN->setEnabled(true);  this->ui->YP->setEnabled(true);
                        this->ui->ZN->setEnabled(true);  this->ui->ZP->setEnabled(true);
                        this->ui->AN->setEnabled(true);  this->ui->AP->setEnabled(true);
                        this->ui->BN->setEnabled(true);  this->ui->BP->setEnabled(true);
                        this->ui->CN->setEnabled(true);  this->ui->CP->setEnabled(true);
                        this->ui->E1N->setEnabled(true); this->ui->E1P->setEnabled(true);
                        this->ui->E2N->setEnabled(true); this->ui->E2P->setEnabled(true);
                    }
                    this->ui->XN->setStyleSheet(("color: rgb(50,150,30)"));  this->ui->XP->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->YN->setStyleSheet(("color: rgb(50,150,30)"));  this->ui->YP->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->ZN->setStyleSheet(("color: rgb(50,150,30)"));  this->ui->ZP->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->AN->setStyleSheet(("color: rgb(50,150,30)"));  this->ui->AP->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->BN->setStyleSheet(("color: rgb(50,150,30)"));  this->ui->BP->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->CN->setStyleSheet(("color: rgb(50,150,30)"));  this->ui->CP->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->E1N->setStyleSheet(("color: rgb(50,150,30)")); this->ui->E1P->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->E2N->setStyleSheet(("color: rgb(50,150,30)")); this->ui->E2P->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel1->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel2->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel3->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel4->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel5->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel6->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel7->setStyleSheet(("color: rgb(50,150,30)"));
                    this->ui->DRLabel8->setStyleSheet(("color: rgb(50,150,30)"));
                }
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Switch_Clicked(){
    static bool onSwitchPage;
    if(onSwitchPage == true){
        onSwitchPage = false;
        if(this->ui->TecControllerSelected->isChecked())
            if(this->pTecControllerHMI != nullptr)  ControllerHmiPage = UnionAllTechHmi;
            else                                    ControllerHmiPage = UnionAllSys;
        else if(this->ui->RobControllerSelected->isChecked())
            if(this->pRobControllerHMI != nullptr)  ControllerHmiPage = UnionAllTc3Robot1;
            else                                    ControllerHmiPage = UnionAllSys;
        else
            ControllerHmiPage = UnionAllSys;
    }
    else{
        ControllerHmiPage = UnionAllSys;
    }
    if(ControllerHmiPage == UnionAllSys){
        onSwitchPage = true;
    }
    else if(ControllerHmiPage == UnionAllTechHmi){
    }
    else if(ControllerHmiPage == UnionAllTc3Robot1){


        this->ui->XN->setEnabled(false);   this->ui->XP->setEnabled(false);
        this->ui->YN->setEnabled(false);   this->ui->YP->setEnabled(false);
        this->ui->ZN->setEnabled(false);   this->ui->ZP->setEnabled(false);
        this->ui->AN->setEnabled(false);   this->ui->AP->setEnabled(false);
        this->ui->BN->setEnabled(false);   this->ui->BP->setEnabled(false);
        this->ui->CN->setEnabled(false);   this->ui->CP->setEnabled(false);

        this->ui->E1N->setEnabled(false);   this->ui->E1P->setEnabled(false);
        this->ui->E2N->setEnabled(false);   this->ui->E2P->setEnabled(false);

        this->ui->XN->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->XP->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->YN->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->YP->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->ZN->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->ZP->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->AN->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->AP->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->BN->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->BP->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->CN->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->CP->setStyleSheet(("color: rgb(0,0,0)"));

        this->ui->E1N->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->E1P->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->E2N->setStyleSheet(("color: rgb(0,0,0)"));   this->ui->E2P->setStyleSheet(("color: rgb(0,0,0)"));

        this->ui->DRLabel1->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel2->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel3->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel4->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel5->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel6->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel7->setStyleSheet(("color: rgb(0,0,0)"));
        this->ui->DRLabel8->setStyleSheet(("color: rgb(0,0,0)"));

        if     (this->ui->RobModeM1Selected->isChecked())       this->pRobControllerHMI->onbtnclicked_ModeSelected(0);
        else if(this->ui->RobModeM2Selected->isChecked())       this->pRobControllerHMI->onbtnclicked_ModeSelected(1);
        else if(this->ui->RobModeAUTOSelected->isChecked())     this->pRobControllerHMI->onbtnclicked_ModeSelected(2);
        else if(this->ui->RobModeREMOTESelected->isChecked())   this->pRobControllerHMI->onbtnclicked_ModeSelected(3);
    }

    this->ui->Main->setCurrentIndex(ControllerHmiPage);
    if(this->pHmiServerHandle != nullptr){
        this->pHmiServerHandle->HmiClientOrder = ControllerHmiPage;
    }
}

void HmiThread :: onbtnclicked_ESTOP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){

            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                if(this->pRobControllerHMI->onbtnclicked_ESTOP_Clicked() == false){
                    this->ui->ESTOP->setStyleSheet(("background-color: rgb(255,255,0)"));
                    if(!(this->ui->vPower->isEnabled())){
                        this->ui->vPower->setEnabled(true);
                    }
                }
                else{
                    this->ui->vPower->setStyleSheet(("background-color: rgb(225,225,225)"));
                    this->ui->ESTOP->setStyleSheet(("background-color: rgb(255,0,0)"));
                    if(this->ui->vPower->isEnabled()){
                        this->ui->vPower->setEnabled(false);
                    }
                    if(!this->ui->XN->isEnabled()){
                        this->ui->XN->setEnabled(false); this->ui->XP->setEnabled(false);
                        this->ui->YN->setEnabled(false); this->ui->YP->setEnabled(false);
                        this->ui->ZN->setEnabled(false); this->ui->ZP->setEnabled(false);
                        this->ui->AN->setEnabled(false); this->ui->AP->setEnabled(false);
                        this->ui->BN->setEnabled(false); this->ui->BP->setEnabled(false);
                        this->ui->CN->setEnabled(false); this->ui->CP->setEnabled(false);
                        this->ui->E1N->setEnabled(false); this->ui->E1P->setEnabled(false);
                        this->ui->E2N->setEnabled(false); this->ui->E2P->setEnabled(false);
                    }
                    this->ui->XN->setStyleSheet(("color: rgb(0,0,0)")); this->ui->XP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->YN->setStyleSheet(("color: rgb(0,0,0)")); this->ui->YP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->ZN->setStyleSheet(("color: rgb(0,0,0)")); this->ui->ZP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->AN->setStyleSheet(("color: rgb(0,0,0)")); this->ui->AP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->BN->setStyleSheet(("color: rgb(0,0,0)")); this->ui->BP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->CN->setStyleSheet(("color: rgb(0,0,0)")); this->ui->CP->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->E1N->setStyleSheet(("color: rgb(0,0,0)")); this->ui->E1P->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->E2N->setStyleSheet(("color: rgb(0,0,0)")); this->ui->E2P->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel1->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel2->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel3->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel4->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel5->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel6->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel7->setStyleSheet(("color: rgb(0,0,0)"));
                    this->ui->DRLabel8->setStyleSheet(("color: rgb(0,0,0)"));
                }
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Setting(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_Setting();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_Setting();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Edit(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_Edit();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_Edit();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Pause(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_Pause();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                if(this->pRobControllerHMI->onbtnclicked_Pause()){
                    this->ui->Pause->setStyleSheet(("background-color: rgb(255,255,0)"));
                }
                else {
                    this->ui->Pause->setStyleSheet(("background-color: rgb(225,225,225)"));
                }
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Run(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_Run();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                if(this->pRobControllerHMI->onbtnclicked_Run()){
                    this->ui->Run->setStyleSheet(("background-color: rgb(50,150,30)"));
                }
                else{
                    this->ui->Run->setStyleSheet(("background-color: rgb(225,225,225)"));
                }

            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Stop(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_Stop();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                if(this->pRobControllerHMI->onbtnclicked_Stop()){
                    this->ui->Stop->setStyleSheet(("background-color: rgb(225,0,0)"));
                }
                else{
                    this->ui->Stop->setStyleSheet(("background-color: rgb(225,225,225)"));
                }

            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_fn1(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_fn1();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_fn1();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_fn2(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_fn2();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_fn2();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_fn3(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_fn3();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_fn3();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_fn4(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_fn4();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_fn4();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_fn1(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnpressed_fn1();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_fn1();
            }
            break;
        default:
            break;
    }
}
void HmiThread :: onbtnpressed_fn2(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnpressed_fn2();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_fn2();
            }
            break;
        default:
            break;
    }
}
void HmiThread :: onbtnpressed_fn3(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnpressed_fn3();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_fn3();
            }
            break;
        default:
            break;
    }
}
void HmiThread :: onbtnpressed_fn4(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnpressed_fn4();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_fn4();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_fn1(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnreleased_fn1();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_fn1();
            }
            break;
        default:
            break;
    }
}
void HmiThread :: onbtnreleased_fn2(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnreleased_fn2();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_fn2();
            }
            break;
        default:
            break;
    }
}
void HmiThread :: onbtnreleased_fn3(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnreleased_fn3();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_fn3();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_fn4(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnreleased_fn4();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_fn4();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Home(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_Home();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_Home();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_MainScriptStatus(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_MainScriptStatus();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_MainScriptStatus();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_SubScriptStatus(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){

            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_SubScriptStatus();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_VisHmi(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
                this->pTecControllerHMI->onbtnclicked_VisHmi();
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnclicked_VisHmi();
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_Coordinate(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                short Coordinate = 0;
                int   ToolID = 0;
                int   WorkID = 0;
                this->pRobControllerHMI->onbtnclicked_Coordinate(Coordinate,ToolID,WorkID);
                switch (Coordinate) {
                case 0:
                    this->ui->DRLabel1->setText("A1");
                    this->ui->DRLabel2->setText("A2");
                    this->ui->DRLabel3->setText("A3");
                    this->ui->DRLabel4->setText("A4");
                    this->ui->DRLabel5->setText("A5");
                    this->ui->DRLabel6->setText("A6");
                    break;
                default:
                    this->ui->DRLabel1->setText("X");
                    this->ui->DRLabel2->setText("Y");
                    this->ui->DRLabel3->setText("Z");
                    this->ui->DRLabel4->setText("A");
                    this->ui->DRLabel5->setText("B");
                    this->ui->DRLabel6->setText("C");
                    break;
                }
                if(ToolID != 0) this->ui->TCPNumber->setNum(ToolID);
                else            this->ui->TCPNumber->setText("Default");

                if(WorkID != 0) this->ui->PCSNumber->setNum(WorkID);
                else            this->ui->PCSNumber->setText("Default");
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_MessageDone(){
    if(ErrorMessage.isEmpty()){
        if(WarningMessage.isEmpty()){
            if(NormalMessage.isEmpty()){
            }
            else{
                NormalMessage.pop_back();
                mMessageNumber.NormalMessageNumber = mMessageNumber.NormalMessageNumber - 1;
                this->ui->NormalMessageNumber->setNum(mMessageNumber.NormalMessageNumber);
            }
        }
        else{
            WarningMessage.pop_back();
            mMessageNumber.WarningMessageNumber = mMessageNumber.WarningMessageNumber - 1;
            this->ui->WarningMessageNumber->setNum(mMessageNumber.WarningMessageNumber);
        }
    }
    else{
        ErrorMessage.pop_back();
        mMessageNumber.ErrorMessageNumber = mMessageNumber.ErrorMessageNumber - 1;
        this->ui->ErrorMessageNumber->setNum(mMessageNumber.ErrorMessageNumber);
    }
}

void HmiThread :: onbtnclicked_MessageAllDone(){
    if(NormalMessage.isEmpty()){
    }
    else{
        NormalMessage.clear();
        mMessageNumber.NormalMessageNumber = 0;
        this->ui->NormalMessageNumber->setNum(mMessageNumber.NormalMessageNumber);
    }
}

void HmiThread :: onbtnclicked_MessageDetail(){

}

void HmiThread :: onbtnpressed_XP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_XP();
                this->ui->XP->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel1->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_YP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_YP();
                this->ui->YP->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel2->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_ZP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_ZP();
                this->ui->ZP->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel3->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_AP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_AP();
                this->ui->AP->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel4->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_BP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_BP();
                this->ui->BP->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel5->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_CP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_CP();
                this->ui->CP->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel6->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_XN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_XN();
                this->ui->XN->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel1->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_YN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                pRobControllerHMI->onbtnpressed_YN();
                this->ui->YN->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel2->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_ZN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_ZN();
                this->ui->ZN->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel3->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_AN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_AN();
                this->ui->AN->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel4->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_BN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_BN();
                this->ui->BN->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel5->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_CN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_CN();
                this->ui->CN->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel6->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_E1P(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_E1P();
                this->ui->E1P->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel7->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_E2P(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_E2P();
                this->ui->E2P->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel8->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_E1N(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_E1N();
                this->ui->E1N->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel7->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnpressed_E2N(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnpressed_E2N();
                this->ui->E2N->setStyleSheet(("color: rgb(255,128,0)"));
                this->ui->DRLabel8->setStyleSheet(("color: rgb(255,128,0)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_XP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_XP();
                this->ui->XP->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel1->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_YP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_YP();
                this->ui->YP->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel2->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_ZP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_ZP();
                this->ui->ZP->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel3->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_AP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_AP();
                this->ui->AP->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel4->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_BP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_BP();
                this->ui->BP->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel5->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_CP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_CP();
                this->ui->CP->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel6->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_XN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_XN();
                this->ui->XN->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel1->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_YN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_YN();
                this->ui->YN->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel2->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_ZN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_ZN();
                this->ui->ZN->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel3->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_AN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_AN();
                this->ui->AN->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel4->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_BN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_BN();
                this->ui->BN->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel5->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_CN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_CN();
                this->ui->CN->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel6->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_E1P(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_E1P();
                this->ui->E1P->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel7->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_E2P(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_E2P();
                this->ui->E2P->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel8->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnreleased_E1N(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_E1N();
                this->ui->E1N->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel7->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}
void HmiThread :: onbtnreleased_E2N(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                this->pRobControllerHMI->onbtnreleased_E2N();
                this->ui->E2N->setStyleSheet(("color: rgb(50,150,30)"));
                this->ui->DRLabel8->setStyleSheet(("color: rgb(50,150,30)"));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_MannualOverrideP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                double value;
                this->pRobControllerHMI->onbtnclicked_MannualOverrideP(value);
                this->ui->ManualOverride->setText(QString::number(value));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_ProgramOverrideP(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                double value;
                this->pRobControllerHMI->onbtnclicked_ProgramOverrideP(value);
                this->ui->ProgramOverride->setText(QString::number(value));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_MannualOverrideN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                double value;
                this->pRobControllerHMI->onbtnclicked_MannualOverrideN(value);
                this->ui->ManualOverride->setText(QString::number(value));
            }
            break;
        default:
            break;
    }
}

void HmiThread :: onbtnclicked_ProgramOverrideN(){
    switch (this->ControllerHmiPage) {
        case UnionAllTechHmi:
            if(this->pTecControllerHMI != NULL){
            }
            break;
        case UnionAllTc3Robot1:
            if(this->pRobControllerHMI != NULL){
                double value;
                this->pRobControllerHMI->onbtnclicked_ProgramOverrideN(value);
                this->ui->ProgramOverride->setText(QString::number(value));
            }
            break;
        default:
            break;
    }
}
